﻿using UnityEngine;
using System.Collections;
using strange.extensions.mediation.impl;
using strange.extensions.context.api;
using strange.extensions.dispatcher.eventdispatcher.api;
using System;

namespace NormalBattleIoc
{
    public class PlayerInfoPanelMediator : Mediator
    {
        [Inject]
        public PlayerInfoPanelView view { get; set; }

        [Inject(ContextKeys.CONTEXT_DISPATCHER)]//全局的dispatcher
        public IEventDispatcher dispatcher { get; set; }

        /// <summary>
        /// 这里做初始化的操作，相当于start
        /// </summary>
        public override void OnRegister()
        {
            // view.ShowThisUI();

           

             dispatcher.AddListener(BattleUIEvent.UpdatePlayerHp , RefreshPlayerAHpFunc );

            // dispatcher.AddListener(BattleUIEvent.Close_All_Panel, OnCloseAll_Panel);
        }

       /// <summary>
       /// 更新读取角色1的HP值
       /// </summary>
        void RefreshPlayerAHpFunc()
        {
            if (view.playerA_Hp != null)
            {
                PlayerInBattle p = PlayerManager.Instance.playerA.GetComponent<PlayerInBattle>();
                view.playerA_Hp.text = p.NowHp + "/" + p.MaxHp;
            }
        }


    }
}
